home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SPRAY.ASM < prev    next >
Assembly Source File  |  1989-07-27  |  6KB  |  157 lines

  1. comment }
  2.   SPRAY.COM      program copyright Dave Angel  71046,1567.
  3.                  free for anybody, as long as it's not included with
  4.                  commercial software.  Nominal charge (under $6) okay.
  5.  
  6.   SPRAY.ASM      This file serves as both documentation and source code.
  7.                  The program was written in response to a message by
  8.                  Joe Wallace 21550,6003, who wanted a program to dump
  9.                  memory after an accidental abort of some other program.
  10.  
  11.                  The program was entered with KEDIT, assembled with MASM
  12.                  5.1, and debugged with SYMDEB.  There are several known
  13.                  simplifications, to keep it small.
  14.  
  15.                  It only parses the command line to the extent that if the
  16.                  command line is non-blank it gives the copyright message.
  17.                  If run with a blank line, it dumps memory from its own end
  18.                  to the 640k boundary.  If you have some other amount of
  19.                  memory, change the line below containing '**memory' as
  20.                  appropriate.
  21.  
  22.                  It outputs to standard out, and you have to redirect it if
  23.                  you want it in a disk file.  So you'd run   SPRAY>C:\temp
  24.                  to get it to dump to a file on C: called temp.
  25.  
  26.                  Finally, it will go somewhat beyond the (640k) limit, as
  27.                  much as 63.9 k beyond.  This is no problem on most
  28.                  systems, you just may get a bit of garbage at the end.
  29.                  But on a few systems you may get funny errors accessing
  30.                  that memory.  If so, the 'nextsegment' logic needs to be
  31.                  tightened up, to handle the final, partial segment.
  32.  
  33.                  Good luck.  Any suggestions or improvements welcome.
  34.                  Dave Angel  Compuserve 71046,1456    or    Genie   D.Angel
  35.                  July 27, 1989
  36.  
  37. }
  38. CGROUP  group  CODE
  39. CODE    segment
  40.         org     100h
  41.      assume  cs:CODE, DS:CODE
  42. start   proc    near
  43.         mov     sp,100h
  44.         cmp     byte ptr ds:[80h],0
  45.         jz      start2
  46.         mov     dx,offset CGROUP:helpmessage
  47.         mov     ah,9
  48.         int     21h
  49.         jmp     next2
  50. helpmessage     db    'SPRAY  copyright 1989 by Dave Angel 71046,1567',13,10
  51.                 db    '   free software to dump memory to stdout',13,10,'$'
  52.  
  53. start2:
  54.         mov     di,offset CGROUP:endcode
  55.         mov     si,offset CGROUP:endcode+5  ; source starting address
  56.         cld
  57.         mov     cx,78
  58.         xor     bx,bx           ; bx is count of printables 'in-a-row'
  59. loop1:
  60.         cmp     si,0fff0h
  61.         jb      loop1a
  62.         call    nextsegment        ; call if we're at end of segment
  63. loop1a:
  64.         lodsb                   ; retrieve one byte
  65.         cmp     al,20h
  66.         jb      loop5
  67.         cmp     al,7fh
  68.         ja      loop5           ; skip if unprintable character
  69. ;  found a printable character
  70. loop2:
  71.         stosb
  72.         inc     bx
  73.         loop    loop1
  74. ; we've printed enough on this line, go to next
  75. loop3:
  76.         mov     al,0dh
  77.         stosb
  78.         mov     al,0ah
  79.         stosb
  80.         call    flushoutput             ; write the data so far
  81.         xor     bx,bx
  82.         loop    loop1
  83.  
  84. ;  We found a non-printable
  85. loop5:
  86.         cmp     bx,3
  87.         ja      loop5a          ; skip if at least 3 printables in a row
  88.         sub     di,bx
  89.         add     cx,bx           ; back up over them, if 3 or less
  90.         jmp     loop5b
  91. loop5a:
  92.         cmp     cx,8
  93.         jb      loop3           ; if near the end of line, make a new one
  94.         mov     al,20h
  95.         stosb
  96.         dec     cx
  97.         stosb           ; otherwise, add two spaces and keep scanning
  98. loop5b:
  99.         dec     cx
  100. loop6:
  101.         xor     bx,bx           ; zero 'printables in-a-row'
  102.         cmp     si,0fff0h
  103.         jb      loop6a
  104.         call    nextsegment        ; call if we're at end of segment
  105. loop6a:
  106.         lodsb
  107.         cmp     al,20h
  108.         jb      loop6
  109.         cmp     al,7fh
  110.         ja      loop6           ; ignore any more unprintables
  111.         jmp     loop2
  112. start   endp
  113.  
  114. flushoutput     proc    near
  115. ;  DI points one beyond last character of buffer.  So write from
  116. ;    endcode to one less than DI
  117.         mov     cx,di
  118.         mov     dx,offset CGROUP:endcode            ; address
  119.         sub     cx,dx           ; count
  120.         mov     bx,1            ; standard out
  121.         mov     ah,40h
  122.         push    ds
  123.         push    cs
  124.         pop     ds
  125.         int     21h             ; write the line to stdout
  126.         pop     ds
  127.      ; ignore errors
  128.         mov     di,offset cgroup:endcode
  129.         mov     cx,78
  130.         ret
  131. flushoutput     endp
  132.  
  133.  
  134. nextsegment     proc    near
  135. ;  this routine is only called when SI exceeds FFF0
  136. ;  here's where we move to another segment, and check for 640k.  We adjust
  137. ;  DS and SI, and return, if still more to do.
  138.  
  139.         push    bx              ; save bx
  140.         mov     bx,0a000h       ; end of **memory assumed to be A000
  141.         mov     ax,ds
  142.         add     ax,0fffh
  143.         sub     si,0fff0h
  144.         mov     ds,ax
  145. ; notice, we're being sloppy here, and dumping as much as 63.9k beyond 640k
  146.         cmp     ax,bx
  147.         jae     next2
  148.         pop     bx              ; restore bx
  149.         ret                     ; return if still more memory to go
  150. next2:
  151.         mov     ax,4c00h
  152.         int     21h
  153. nextsegment     endp
  154. endcode label   byte
  155. CODE    ends
  156.         end     start
  157.